<?php


namespace app\mobile\controller;


use app\BaseController;
use think\facade\Db;
class ProvCityArea extends Base
{
    /**
     * @return \think\response\Json
     * 省市区全部
     */
    public function all(){
        $prov = Db::name('cn_prov')->field('code,name')->select()->toArray();
        foreach ($prov as &$v) {
            $v['city'] = Db::name('cn_city')->field('code,name')->where('pcode', $v['code'])->select()->toArray();
            foreach ($v['city'] as &$vv){
                // $vv['area'] = Db::name('cn_area')->field('name')->where('pcode', $vv['code'])->select();
            }
        }
        return json(['code' => 200, 'message' => '省市区', 'data' => $prov]);
    }

    /**
     * 省
     */
    public function get_prov()
    {
        $prov = Db::name('cn_prov')->field('code,name')->select()->toArray();
        return json(['code' => 200, 'message' => '省', 'data' => $prov]);
    }

    /**
     * 市
     */
    public function get_city()
    {
        $prov = Db::name('cn_city')->field('code,name')->where('pcode', $this->param['code'])->select()->toArray();
        return json(['code' => 200, 'message' => '省', 'data' => $prov]);
    }

    /**
     * 区
     */
    public function get_area()
    {
        $prov = Db::name('cn_area')->field('code,name')->where('pcode', $this->param['code'])->select()->toArray();
        return json(['code' => 200, 'message' => '省', 'data' => $prov]);
    }


}